#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<stdio.h>
#include<string.h>

#define MAX_WORDS 20
#define MAX_LENGTH 10
int main()
{
    char words[MAX_WORDS][MAX_LENGTH];
    int n = 0;

    //char word[MAX_LENGTH];
    while (1)
    {
        scanf("%s", words[n]);
        if (words[n][0] == '#')
        {
            break;
        }
        //strcpy(words[num_words],word);
        n++;
    }

    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < n - i - 1; j++)
        {
            if (strlen(words[j]) > strlen(words[j + 1]) || (strlen(words[j]) == strlen(words[j + 1]) && strcmp(words[j], words[j + 1] > 0)))
            {
                char temp[MAX_LENGTH];
                strcpy(temp, words[j]);
                strcpy(words[j], words[j + 1]);
                strcpy(words[j + 1], temp);
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        printf("%s", words[i]);
    }
    return 0;
}
int main10()
{
    int N;
    scanf("%d", &N);
    getchar();
    char arr[1001];
    fgets(str, 1001, stdin);
    int len = strlen(str);
    if (str[len - 1] == '\n');
    {
        str[len - 1] = '\0';
        len--;
    }
    int rows = len / N;
    if (len % N != 0)
    {
        rows++;
    }
    char grid[rows][N];
    int index;

    for (int j = N - 1; j >= 0; j++)
    {
        for (int i = 0; i < rows; i++)
        {
            if (index < len)
            {
                grid[i][j] = str[index++];
            }
            else
            {
                grid[i][j] = ' ';
            }

        }
    }
    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < N; j++)
        {
            printf("%c", grid[i][j]);
        }
        printf("\n");
    }
    return 0;
}
int main1()
{
    int N;
    scanf("%d", &N);
    int arr[5];
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &arr[i]);
    }
    int m, n;
    scanf("%d", &m);
    n = m;
    while (n == m)
    {
        for (int i = 0; i < N; i++)
        {
            if (arr[i] > m)
            {
                arr[i] = m;
                N++;
            }
        }
    }
    for (int i = 0; i < N; i++)
    {
        printf("%d", arr[i]);
    }
    return 0;
}
int max(int a, int b)
{
    return a > b ? a : b;
}
int main()
{
    char str[1001];
    fgets(str, 1001, stdin);

    int len = strlen(str);
    if (str[len - 1] == '\n');
    {
        str[len - 1] = '\0';
        len--;
    }
    int max_len = 0;
    for (int i = 0; i < len; i++)
    {
        int left = i;
        int right = i;
        while (left >= 0 && right < len && str[left] == str[right])
        {
            max_len = max(max_len, right - left + 1);
                left--;
            right++;
        }
        left = i;
        right = i + 1;
        while (left >= 0 && right < len && str[left] == str[right])
        {
            max_len = max(max_len, right - left + 1);
            left--;
            right++;
        }
    }
    printf("%d\n", max_len);
    return 0;

}